package com.yc.websocket;

import com.yc.websocket.bean.WebSocketProperties;
import com.yc.websocket.biz.DefalutMsgSender;
import com.yc.websocket.biz.IMsgSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@AutoConfiguration
@ComponentScan("com.yc.websocket")
@ConditionalOnProperty(prefix = "websocket",name="enable")
@EnableConfigurationProperties(WebSocketProperties.class)
public class WebSocketConfiguration {
    @Bean
    public ServerEndpointExporter serverEndpointExporter(){
        return new ServerEndpointExporter();
    }

    @Bean
    //没这个bean就用这个
    @ConditionalOnMissingBean(IMsgSender.class)
    public IMsgSender msgSender(){
        return new DefalutMsgSender();
    }
}
